#@layout()
#define script()
<script src="/static/components/ckeditor/ckeditor.js"></script>
<script src="/static/components/selectize/selectize.min.js"></script>


<script>

    initEditor('editor1');

    $('.article-tags').selectize({
        plugins: ['remove_button'],
        delimiter: ',',
        persist: false,
        addPrecedence: true,
        create: true
    });


    function doSubmit() {
        editorUpdate();
        $("#form").ajaxSubmit({
            type: "post",
            success: function (data) {
                if (data.state == "ok") {
                    $("#pageId").attr("value", data.id);
                    toastr.success('文章保存成功。');
                } else {
                    toastr.error(data.message, '操作失败');
                }
            },
            error: function () {
                alert("信息提交错误");
            }
        });
    }


    $("#submit").on("click", function () {
        $("#pageStatus").val("normal");
        doSubmit();
    })

    $("#draft").on("click", function () {
        $("#pageStatus").val("draft");
        doSubmit();
    })

    $("#trash").on("click", function () {
        $("#pageStatus").val("trash");
        doSubmit();
    })

    $("#chooseThumbnail").on("click", function () {
        layer.open({
            type: 2,
            title: '选择图片',
            anim: 2,
            shadeClose: true,
            shade: 0.5,
            area: ['80%', '70%'],
            content: '/admin/attachment/browse',
            end: function () {
                if (layer.data.src != null) {
                    $("#thumbnail").attr("src", layer.data.src);
                    $("#articleThumbnail").val(layer.data.src);
                }
            }
        });
    })


    $("#removeThumbnail").on("click", function () {
        $("#thumbnail").attr("src", "/static/admin/images/nothumbnail.jpg");
        $("#articleThumbnail").val("");
    })


</script>
#end
#define css()
<link href="/static/components/selectize/css/selectize.css" rel="stylesheet">
<link href="/static/components/selectize/css/selectize.jpress.css" rel="stylesheet">
#end

#define content()
<div class="content-wrapper">

    <section class="content-header">
        <h1>
            关键字与内容
        </h1>
    </section>

    <section class="content">
        <form action="/admin/page/doWriteSave" method="post" id="form">
            <input type="hidden" id="pageStatus" name="page.status" value='#(page.id ?? "normal")'>
            <input type="hidden" id="pageId" name="page.id" value="#(page.id ??)">
            <div class="row">
                <div class="col-xs-9">

                    <!-- /.box-header -->
                    <!-- form start -->
                    <div class="form-horizontal">
                        <div class="form-group">
                            <div class="col-sm-12">
                                <input type="input" class="form-control input-lg" name="page.title"
                                       placeholder="请输入标题"
                                       value="#(page.title ??)">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-12" style="z-index: 9999;">
                                <textarea id="editor1" name="page.text"
                                          style="height: 467px;width: 100%;background-color: white">
                                #escape(page.text ??)
                                </textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-12">
                                <div class="box box-solid">
                                    <div class="box-header with-border">
                                        <h3 class="box-title">属性设置</h3>

                                        <div class="box-tools">
                                            <button type="button" class="btn btn-box-tool" data-widget="collapse">
                                                <i class="fa fa-minus"></i>
                                            </button>
                                        </div>
                                    </div>
                                    <!-- /.box-header -->
                                    <div class="box-body ">
                                        <!-- Custom Tabs -->

                                        <form class="form-horizontal" autocomplete="off">
                                            <div class="box-body ">


                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">链接Slug</label>
                                                    <div class="col-sm-6">
                                                        <input type="input" class="form-control" placeholder=""
                                                               name="page.slug" value="#(page.slug ??)">
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">样式</label>
                                                    <div class="col-sm-6">
                                                        <select class="form-control" name="page.style">
                                                            <option>请选择样式</option>
                                                        </select>
                                                    </div>
                                                </div>

                                                <!--<h4 class="page-header">搜索优化</h4>-->

                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">SEO关键字</label>

                                                    <div class="col-sm-6">
                                                    <textarea rows="3" class="form-control" name="page.meta_keywords"
                                                              placeholder="请输入">#(page.meta_keywords ??)</textarea>
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">SEO描述</label>

                                                    <div class="col-sm-6">
                                                    <textarea rows="3" class="form-control"
                                                              name="page.meta_description"
                                                              placeholder="请输入">#(page.meta_description ??)</textarea>
                                                    </div>
                                                </div>


                                            </div>

                                        </form>
                                        <!-- nav-tabs-custom -->
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

                <div class="col-xs-3">
                    <div class="box box-solid">

                        <!-- /.box-header -->
                        <!-- form start -->
                        <div class="box-body ">
                            <button type="button" id="submit" class="btn btn-primary btn-sm ">发布</button>
                            <button type="button" id="draft" class="btn btn-default btn-sm ">草稿</button>

                            <a href="javascript:;" id="trash" class="pull-right" style="padding-top: 5px;">移至垃圾箱</a>
                        </div>
                    </div>


                    <div class="box box-solid">
                        <div class="box-header with-border ">
                            <h3 class="box-title">缩略图</h3>
                        </div>
                        <div class="box-body no-padding">
                            <img src="#(page.thumbnail ??'/static/admin/images/nothumbnail.jpg')"
                                 style="width: 100%;height: 200px"
                                 id="thumbnail">
                            <input type="hidden" value="#(page.thumbnail ??)" name="page.thumbnail"
                                   id="articleThumbnail">
                        </div>
                        <div class="box-footer">
                            <button type="button" class="btn btn-default btn-sm " id="chooseThumbnail">选择图片</button>
                            <a href="javascript:;" style="padding-left: 15px" id="removeThumbnail">移除</a>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </section>

</div>
#end
